<?php
/**
 * @file
 * Contains \Drupal\discogs\Controller\ReleaseController.
 */

namespace Drupal\discogs\Controller;

use Drupal\discogs\ReleaseInterface;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

/**
 * Controller routines for ReleaseController routes.
 */
class ReleaseController extends ControllerBase {
	public function ReleaseEntityPage(ReleaseInterface $release) {
		$view_builder = \Drupal::entityManager()->getViewBuilder('release');
		$build = $view_builder->view($release);
		return $build;
	}
	
	public function ReleaseEntityPageMarc21(ReleaseInterface $release) {
		$view_builder = \Drupal::entityManager()->getViewBuilder('release');
		$build = $view_builder->view($release, 'marc21');
		return $build;
	}
	
	public function ReleaseEntityPageTitle(ReleaseInterface $release) {
		$title='';
		$artists=[];
		foreach($release->get('artists') as $artist) {
			$artists[]=$artist['name'].' '.$artist['join'].' ';
		}
		return sprintf("%s - %s", substr(implode($artists), 0, -2-strlen($artist['join'])), $release->get('title'));
	}
}

?>
